package clientApp;

import game.units.Character;

import clientApp.utils.CharNode;
import clientApp.utils.RPG_Workstation_Container;

/**
 *
 * @author Gabriel
 */
@SuppressWarnings("serial")
public class MyCharacters extends javax.swing.JPanel {

	RPG_Workstation_Container container;	
	CharNode  charNode;
	RPG_Workstation frame;

	/** Creates new form MyCharacters */
    public MyCharacters(RPG_Workstation frame, RPG_Workstation_Container rpg_Workstation_Container) {
    	container = rpg_Workstation_Container;
    	this.frame = frame;
    	initCharacters();
        initComponents();
        
    }

    public void initCharacters() {
		//por enquanto
    	charNode = new CharNode();		
	}
    
    public void refreshCharacters()
    {
    	charNode.setCharacters(Character.getDNDCharacters());
    }

    private void initComponents() {

        jPanel1 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel5 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jBViewSheet = new javax.swing.JButton();
        jBLvlUp = new javax.swing.JButton();
        jBDelChar = new javax.swing.JButton();
        jBEditChar = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();

        jPanel1.setBackground(new java.awt.Color(0, 0, 102));
        jPanel1.setMinimumSize(new java.awt.Dimension(786, 600));
        jPanel1.setPreferredSize(new java.awt.Dimension(800, 600));

        jLabel1.setFont(new java.awt.Font("Tahoma", 0, 28));
        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setText("My Characters");

        jLabel5.setFont(new java.awt.Font("Tahoma", 0, 18));
        jLabel5.setForeground(new java.awt.Color(255, 255, 255));
        jLabel5.setText("Character List");

        charNode = new CharNode();
        charNode.setCharacters(Character.getDNDCharacters());        
        jTable1.setModel(charNode);
        
        jTable1.setColumnSelectionAllowed(true);
        jTable1.getTableHeader().setReorderingAllowed(false);
        jScrollPane1.setViewportView(jTable1);
        jTable1.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jTable1.setRowSelectionAllowed(true);
        
        jBViewSheet.setText("View Character Sheet");
        jBViewSheet.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBViewSheetActionPerformed(evt);
            }
        });

        jBLvlUp.setText("Level Up");
        jBLvlUp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBLvlUpActionPerformed(evt);
            }
        });

        jBDelChar.setText("Delete Character");
        jBDelChar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBDelCharActionPerformed(evt);
            }
        });

        jBEditChar.setText("Edit Character");
        jBEditChar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jBEditCharActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 584, Short.MAX_VALUE))
                    .addComponent(jSeparator2, javax.swing.GroupLayout.DEFAULT_SIZE, 766, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 655, Short.MAX_VALUE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator3, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                            .addComponent(jSeparator5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 308, Short.MAX_VALUE)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(24, 24, 24)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(jBDelChar)
                                    .addComponent(jBEditChar)
                                    .addComponent(jBLvlUp)
                                    .addComponent(jBViewSheet))))))
                .addContainerGap())
        );

        jPanel1Layout.linkSize(javax.swing.SwingConstants.HORIZONTAL, new java.awt.Component[] {jBDelChar, jBEditChar, jBLvlUp, jBViewSheet});

        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jBEditChar)
                        .addGap(18, 18, 18)
                        .addComponent(jBDelChar)
                        .addGap(18, 18, 18)
                        .addComponent(jBLvlUp)
                        .addGap(18, 18, 18)
                        .addComponent(jBViewSheet)
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 532, Short.MAX_VALUE))
                .addContainerGap())
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 786, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 650, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jBLvlUpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBLvlUpActionPerformed
        if(jTable1.getSelectedRow() >= 0)
        {
        	if(charNode.characters.get(jTable1.getSelectedRow()).getTotalLevel() < charNode.characters.get(jTable1.getSelectedRow()).getLevel())
        	{
        		container.add(new CharacterBuilder2(container, charNode.characters.get(jTable1.getSelectedRow()), null, false), "CharacterBuilder2");
            	container.panels.show(container, "CharacterBuilder2");
        	}
        }
    }//GEN-LAST:event_jBLvlUpActionPerformed

    private void jBEditCharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBEditCharActionPerformed
    	container.add(new CharacterBuilder1(container, charNode.characters.get(jTable1.getSelectedRow()), false), "CharacterBuilder1");
    	container.panels.show(container, "CharacterBuilder1");
    }//GEN-LAST:event_jBEditCharActionPerformed

    private void jBDelCharActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBDelCharActionPerformed
    	Character.removeDNDCharacter(charNode.characters.get(jTable1.getSelectedRow()));
    	charNode.characters.remove(jTable1.getSelectedRow());    	
    	jTable1.repaint();
    }//GEN-LAST:event_jBDelCharActionPerformed

    private void jBViewSheetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jBViewSheetActionPerformed
    	CharacterBuilder7 comp = new CharacterBuilder7(container, charNode.characters.get(jTable1.getSelectedRow()), null, false);
    	comp.characterSheet = true;
    	comp.saveButtontext();
    	container.add(comp, "CharacterBuilder7");
    	container.panels.show(container, "CharacterBuilder7");
    	
    }//GEN-LAST:event_jBViewSheetActionPerformed

    private javax.swing.JButton jBDelChar;
    private javax.swing.JButton jBEditChar;
    private javax.swing.JButton jBLvlUp;
    private javax.swing.JButton jBViewSheet;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JTable jTable1;
    // End of variables declaration//GEN-END:variables
}
